
//滚动条
$(function(){
	$(":text").addClass('input-text');
	
	$(".ckSelect").click(function(){
		var ck_name = $(this).attr('ck_name');
		var ck_type = $(this).attr('ck_type');
		if(ck_type == 'all'){
			$("input[name='"+ck_name+"']").each(function() {
				this.checked=true;
			});
		}else if(ck_type == 'none'){
			$("input[name='"+ck_name+"']").each(function() {
				this.checked=false;
			});
		}else{
			$("input[name='"+ck_name+"']").each(function() {
				if(this.checked){
					this.checked=false;
				}else{
					this.checked=true;
				}
			});
		}
	})
})

//禁止选择一级分类
function check_cate(obj){ 
	var level=parseInt($("option:selected",$(obj)).attr('level'));
	var pid=parseInt($("option:selected",$(obj)).attr('pid'));
	if(pid==0||level==0||level==1){
		alert("一级、二级分类禁止选择!");
		$('option[value="0"]',$(obj)).attr('selected','selected');
	}
}

//是否显示
function isShow(action_url,id,col_name){
	//document.location.href = action_url+"&id="+"&col_name="+col_name;
	$.get(action_url, { id: id, col_name: col_name }, function(jsondata){
	  	var imgObj = $("#"+col_name+"_"+id+" img");
	  	var imgObjSrc = imgObj.attr("src");
	  	var imgObjSrcNew = imgObjSrc.replace(/(.is_show_)\d+(.png)/gi,"$1"+jsondata+"$2");
	  	imgObj.attr("src",imgObjSrcNew);
	},'json'); 
}

//排序方法
function ordlist(action_url,id,col_name,col_value){
	//document.location.href = action_url+"&id="+"&col_name="+col_name+"&col_value="+col_value;
	//排序的值未发生变化则不提交数据
	if(!isDigit(col_value)){
		alert("请输入正确的数字");
		return;
	}else if(col_value==$("#"+col_name+"_upd_"+id).attr('value')){
		return;
	}else{
		$.get(action_url, { id: id, col_name: col_name,col_value:col_value }, function(jsondata){
			$("#"+col_name+"_"+id).attr('value', jsondata);
			$("#"+col_name+"_upd_"+id).html("已更新");
			$("#"+col_name+"_upd_"+id).attr("value",jsondata);
		},'json'); 
	}
}

function initArea(action_url,province,city,district){
	if($.trim(province)==''){
		province = -1;
	}
	if($.trim(city)==''){
		city = -1;
	}
	if($.trim(district)==''){
		district = -1;
	}
	if(province != -1){
		//父ID=1：中国
		loadArea(action_url,"1","province",province,false);
		
		if(city != -1 ){
			loadArea(action_url,province,"city",city,false);
			if(district != -1){
				loadArea(action_url,city,"district",district,false);
			}else{
				loadArea(action_url,city,"district",district);
			}
		}else{
			loadArea(action_url,province,"city",city);
		}
	}else{
		//
		loadArea(action_url,"1","province",province);
	}
}

function loadArea(action_url,area_id,area_type,default_id,init_flag) {
	if(init_flag!==false){
		init_flag = true;
	}
    $.get(action_url,{"area_id":area_id},function(data){
    	if(area_type=='province'){
    		$('#'+area_type).html('<option value="-1">省份/直辖市</option>');
    		//防止异步加载冲掉信息
    		if(init_flag){
    			$('#city').html('<option value="-1">市/县</option>');
                $('#district').html('<option value="-1">镇/区</option>');
    		}
    		 
    	}else if(area_type=='city'){
           $('#'+area_type).html('<option value="-1">市/县</option>');
         //防止异步加载冲掉信息
           if(init_flag){
        	   $('#district').html('<option value="-1">镇/区</option>');
           } 
        }else if(area_type=='district'){
           $('#'+area_type).html('<option value="-1">镇/区</option>');
        }
        if(area_type!='null' && data != null){
            $.each(data,function(no,items){
                $('#'+area_type).append('<option value="'+items.area_id+'">'+items.area_name+'</option>');
            });
            $('#'+area_type).val(default_id);
        }
        
    });
}

function getSimpleEditor(ke_obj,content_id){
	content_editor = ke_obj.create(content_id, {
		resizeType : 2,
		minWidth:500,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link', 'template', 'fullscreen']
	});
	return content_editor;
}